﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ActiveStoryTouch.DataModel;
using ActiveStoryTouch.UI.Enums;

namespace ActiveStoryTouch.UI.Dialogs
{
    /// <summary>
    /// Interaction logic for GestureTargetDialog.xaml
    /// </summary>
    public partial class GestureTargetDialog : Window
    {
        private SessionManager _sessionManager = null;

        //public Gesture SelectedGesture { get; private set; }
        //public Behavior SelectedBehavior { get; private set; }
        public ActiveStoryTouch.DataModel.Page SelectedPage { get; private set; }

        //public Dictionary<KeyValuePair<Gesture, Behavior>, ActiveStoryTouch.DataModel.Page>

        public GestureTargetDialog(SessionManager sessionManager)
        {
            InitializeComponent();
            _sessionManager = sessionManager;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //foreach (Gesture gesture in _sessionManager.CommonGestureManager.GestureList)
            //{
                //TreeViewItem gestureItem = new TreeViewItem { DataContext = gesture, Header = gesture.DisplayName, ToolTip = gesture.Description };
                //TreeViewItem behaviorItem = new TreeViewItem { Header = "Navigate", DataContext = Behavior.Navigate };
                //behaviorItem.Selected += new RoutedEventHandler(delegate(object selectedSender, RoutedEventArgs selectedEventArgs) 
                //    {
                        //PageListBox.ItemsSource = null;
                        PageListBox.ItemsSource = _sessionManager.CurrentProject.PageDictionary.ValueObservableCollection;
                //    });
                //gestureItem.Items.Add(behaviorItem);
                //GestureTreeView.Items.Add(gestureItem);
            //}
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            String errorMsg = null;
            //if (GestureTreeView.SelectedItem == null)
            //{
            //    errorMsg = "gesture";
            //}
            //else if ((GestureTreeView.SelectedItem as TreeViewItem).Parent == null)
            //{
            //    errorMsg = "behavior";
            //}
            //else 
            if (PageListBox.SelectedItem == null || PageListBox.SelectedIndex == -1)
            {
                errorMsg = "target page";
            }
            if (errorMsg != null)
            {
                MessageBox.Show(this, String.Format("Please select a {0} before proceeding.", errorMsg), "Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }
            //SelectedBehavior = (Behavior)(GestureTreeView.SelectedItem as TreeViewItem).DataContext;
            //SelectedGesture = ((GestureTreeView.SelectedItem as TreeViewItem).Parent as TreeViewItem).DataContext as Gesture;
            SelectedPage = PageListBox.SelectedItem as ActiveStoryTouch.DataModel.Page;
            DialogResult = true;
        }

    }
}
